//namestr.cpp
#include "namestr.h"
#include "../include/HashTable.h"

int NameStr::Construct()
{
	m_stLastTime=0;
	m_u16SubSec=0;
	m_iLen=16;
	return 0;
}
int NameStr::Destruct()
{
	return 0;
}

int NameStr::Init(IN int iLen)
{
	m_stLastTime=time(NULL);
	m_u16SubSec=0;
	if(iLen>0&&iLen<=16) m_iLen=iLen;
	else m_iLen=16;
	return 0;
}

int NameStr::AddSubSec(OUT char *pcOut)
{
	int iRet=-1,i;
	int iResult,iTemp;
	int iDiv=m_u16SubSec,iAdd;

	for(i=0;i<m_iLen;i++)
	{
		if((m_u16SubSec>>i)&1)
		{
			if(pcOut[i]<'A') pcOut[i]+=23;
			else pcOut[i]+=16;
		}
	}

	iRet=0;
_Exit:
	return iRet;
}

int NameStr::CreateStr(OUT char *pcOut)
{
	int iRet=-1,i;
	int iResult,iTemp;
	int iDone=0;
	time_t stTime;
	U8 *pu8_Read;
	U64 u64_Time;

	stTime=time(NULL);
	if(stTime>m_stLastTime)
	{
		m_u16SubSec=0;
		m_stLastTime=stTime;
	}
	else m_u16SubSec++;

	for(i=0;i<m_iLen;i++)
	{
		u64_Time=stTime>>(i<<2);
		u64_Time&=0x0F;
		pcOut[i]=g_cUpHexAry[u64_Time];
	}
	AddSubSec(pcOut);

	iRet=0;
_Exit:
	return iRet;
}